package heima.FangXing.day10.TreeSet;

import heima.FangXing.day10.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo3 {

    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int ageResult = o1.getAge() - o2.getAge();
                int nameResult = ageResult==0?o1.getName().compareTo(o2.getName()):ageResult;
                int result = nameResult==0?1:nameResult;
                return result;
            }
        });

        ts.add(new Student("赵六",26));
        ts.add(new Student("李四",24));
        ts.add(new Student("张三",23));
        ts.add(new Student("王五",25));

        System.out.println(ts);



    }
}
